package com.bbx.aliyunapi.config;


import com.aliyun.rds20140815.Client;
import com.aliyun.teaopenapi.models.Config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RdsClientConfig {


    @Value("${aliyun.ecs.accessKeyId}")
    private String accessKeyId;
    @Value("${aliyun.ecs.accessSecret}")
    private String accessSecret;

    private static Config config;

    private static Client client;

    private RdsClientConfig() { }


    public Client getClient() {
        if (config== null) {
            initClient();
        }
        return client;
    }


    private void initClient() {
        log.info("[{}]", "init Rds Client ~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        config = new Config().setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessSecret);
        // 访问的域名
        config.endpoint = "rds.aliyuncs.com";
        try {
            client = new Client(config);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }




}
